package com.ftg.learn.sys.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ftg.learn.comm.entity.sys.Clazz;
import com.ftg.learn.sys.user.mapper.ClazzMapper;
import com.ftg.learn.sys.user.mapper.EmployeeMapper;
import com.ftg.learn.sys.user.service.IClazzService;
import com.ftg.learn.util.ResBean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * <p>
 * 班级信息 服务实现类
 * </p>
 *
 * @author kangjx
 * @since 2022-10-30
 */
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements IClazzService {

    @Resource
    ClazzMapper clazzMapper;

    @Resource
    EmployeeMapper employeeMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public ResBean delClazzById(Integer id) {

        if(Objects.isNull(clazzMapper.selectById(id))){
            return ResBean.noData();
        }
        employeeMapper.setClazzIdWithNull(id);
        clazzMapper.deleteById(id);
        return ResBean.success();
    }
}
